<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="author" content="zhupeng">
	<title>汇率管理</title>
	<script language="javascript" src="/script/common.js" type="text/javascript"></script>
	<script language="javascript" type="text/javascript">
		//全局变量
		var org = Common.cOrg();	//当前单位	
		var qt = {};
		//页面加载方法
		function load(){
			Eui.showNavigation();
			setPages(["listview","detview"]);
			//初始化汇率类型(查询form)
			var subCurrency = Common.getSubsetItems("currency", [2])
			Common.initDict(searchForm.currency,subCurrency,"全 部");
			//初始化状态(查询form)
			Common.initDict(searchForm.status,"exchangerate_status","全 部");
			
			Common.initDict(exchangeRateForm.currency,subCurrency,"请选择");
			//初始化时间(查询form)
			//Templet.initBeginDateInput("beginDateTd","起始日期","searchForm","beginDate","endDate","_pastDate");
			//Templet.initEndDateInput("endDateTd","结束日期","searchForm","beginDate","endDate","date");
					
			createTable();		
		}				

		//设置表格数据列
		function createTable(){
			var columns = [];
			columns[0]={type:"checkbox"}
			columns[8] = {title:"操作",width:"18%",render:operator,align:"center",order:false} 
			qt = new QueryTable("exchangerate_query","searchForm","datalist",columns,{
				buttons:[
					{value:"添加汇率",actions:onNew}
				]
			});
		}
		function operator(v,r){
			var start =" <a href=# onclick=\"startExchangeRate("+r[0]+");return false;\">启用</a>";
			var del = " <a href=# onclick=delExchangeRate('"+r[0]+"')>删除</a>"
			
			if(r[8] == ExchangeRateStatus.INITED){
				return "<div style='color:gray'> "+start+del+ "</div>"
			}else{
				return "--"
			} 
		}
		function onNew(){
			var form = $("exchangeRateForm");
			form.reset();
			form.statusText.value = Common.getText("exchangerate_status",ExchangeRateStatus.INITED)
			form.creatorName.value = Common.cOperator().name
			switchPage("detview");
		}
		function onSave(){
			if(!checkForm("exchangeRateForm"))return;
			var exchangeRate = Common.getValues("exchangeRateForm");
			var isNew = !exchangeRate.id?true:false
			if(showQuestion(isNew?"您确认要修改汇率吗?":"您确认要增加新汇率吗？")){
				exchangeRate.rate = exchangeRate.rate * 10000 
				DWR.call('exchangeRateService.saveExchangeRate',exchangeRate ,function(v){
					showInformation("汇率"+(isNew?"增加":"修改")+"成功!")
					switchPage("listview");
					qt.showTable()
				});
			}
		}
		function onEdit(id){
			DWR.call('ejbQueryService.loadData','load_exchangerate',{id:id},function(result){
				var er = result[0];
				er.creatorName = result[1];
				er.statusText = Common.getText("exchangerate_status",er.status);
				er.rate = Math.round(er.rate * 1.0 / 10000)
				Common.setValues("exchangeRateForm", er);
				
				switchPage("detview");
			});
		}
		function startExchangeRate(id){
			if(!id){showWarning("汇率编号为空！");return;}
			
			if(showQuestion("您确认要启用编号为"+id+"汇率吗?")){
				DWR.call('exchangeRateService.startExchangeRate',id,function(v){
					showInformation("汇率启用成功!")
					qt.showTable()
				});
			}
		}
		function delExchangeRate(id){
			if(id){
				Eui.onDel("exchangeRateService.deleteExchangeRate",id, "汇率", null, function() {
					qt.showTable();
				},qt.getBts());
			}else{
				showWarning("请选择要删除的汇率");
			}
		}
	</script>
</HEAD>
<body onload="load()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<!--查询静态页面部分-->
	<div id="listview" >	
		<!--查询条件form-->
		<form id="searchForm" name="searchForm" action="">
			<div class="searchForm">
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="label4">
					<tr>
						<td><label>汇率编号</label> <input type="text" name="rateId" onblur="checkV(this,'number')" maxlength="12" ></td>
						<td><label>汇率类型</label> <select name="currency"><option></option></select></td>	
						<td><label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label> <select name="status""><option></option></select></td>	
						<td><button type="button" onclick="qt.showTable()">查 询</button></td> 
					</tr>	
				</table>
			</div>
		</form>
		<!--查询结构列表-->
			<div id="datalist"></div>	
	</div>		
	<!--明细(新增)静态页面部分-->			
	
	<div id="detview" style="display:none;" align="center">
		<div class="form">
			<div class="formTitle">汇率管理</div>
				<form id="exchangeRateForm" name="exchangeRateForm" action="">
					<input type="hidden" name="id">
					<input type="hidden" name="status">
					<input type="hidden" name="creator">
					<table cellSpacing=0 cellPadding=4 width="100%" border=0>
						<tr>
							<td><label>币&nbsp;&nbsp;&nbsp;&nbsp;种</label> <select name="currency" onblur="checkV(this,'',true)"><option></option></select><span class="des">*</span></td>   
							<td><label>汇&nbsp;&nbsp;&nbsp;&nbsp;率</label> <input type="text"  name="rate" onblur="checkV(this,'double',true)"><span class="des">*</span><font color=gray>(一外币兑换多少人民币)</font></td>   
						</tr>	
						<tr>
							<td><label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label> <input type="text" name="statusText" readonly class="readonly" ></td>    
							<td><label>维护人员</label> <input type="text" name="creatorName" readonly class="readonly" ></td> 
						</tr>
					</table>
				</form>
			</div>
			<p><button type='button' id='saveBut' onclick='onSave()'>保 存</button> <button type="button" id="saveBut" onclick="switchPage('listview')">取 消</button></p>
	</div>
 </body>
</html>